#include "Vector.h"
#include <math.h>

Vector2::Vector2()
{
	x = 0;
	y = 0;
}
Vector2::Vector2(float _x, float _y)
{
	x = _x;
	y = _y;
}
Vector2::~Vector2()
{
}
Vector2 Vector2::operator+(Vector2 right)
{
	return Vector2(x + right.x, y + right.y);
}
Vector2 Vector2::operator-(Vector2 right)
{
	return Vector2(x - right.x, y - right.y);
}
Vector2 Vector2::operator*(float right)
{
	return Vector2(x * right, y * right);
}
Vector2 Vector2::operator*(Vector2 right)
{
	return Vector2(x * right.x, y * right.y);
}
Vector2 Vector2::operator/(float right)
{
	return Vector2(x / right, y / right);
}
void Vector2::operator+=(Vector2 right)
{
    x += right.x;
    y += right.y;
}
void Vector2::operator-=(Vector2 right)
{
    x -= right.x;
    y -= right.y;
}
void Vector2::operator*=(float right)
{
    x *= right;
    y *= right;
}
void Vector2::operator/=(float right)
{
    x /= right;
    y /= right;
}
void Vector2::Normalize()
{
	float length = 1.0f/sqrt(x*x + y*y);
	x *= length;
	y *= length;
}

Vector3::Vector3()
{
    x = 0;
    y = 0;
    z = 0;
}
Vector3::Vector3(float _x, float _y, float _z)
{
    x = _x;
    y = _y;
    z = _z;
}
Vector3::~Vector3()
{
}
Vector3 Vector3::operator+(Vector3 right)
{
    return Vector3(x+right.x, y+right.y, z+right.z);
}
Vector3 Vector3::operator-()
{
	return Vector3(-x, -y, -z);
}
Vector3 Vector3::operator-(Vector3 right)
{
    return Vector3(x-right.x, y-right.y, z-right.z);
}
Vector3 Vector3::operator*(float right)
{
    return Vector3(x*right, y*right, z*right);
}
Vector3 Vector3::operator*(Vector3 right)
{
	return Vector3(x*right.x, y*right.y, z*right.z);
}
Vector3 Vector3::operator/(float right)
{
    return Vector3(x/right, y/right, z/right);
}
void Vector3::operator+=(Vector3 right)
{
    x += right.x;
    y += right.y;
    z += right.z;

}
void Vector3::operator-=(Vector3 right)
{
    x -= right.x;
    y -= right.y;
    z -= right.z;
}
void Vector3::operator*=(float right)
{
    x *= right;
    y *= right;
    z *= right;
}
void Vector3::operator/=(float right)
{
    x /= right;
    y /= right;
    z /= right;
}
void Vector3::operator=(Vector3 right)
{
    x = right.x;
    y = right.y;
    z = right.z;
}
void Vector3::Normalize()
{
	float length = Length();

	x /= length;
	y /= length;
	z /= length;
}
float Vector3::Length()
{
	return sqrt(x*x + y*y + z*z);
}
Vector3 Vector3::Cross(Vector3 A, Vector3 B)
{
	return Vector3
	(
		A.y*B.z - A.z*B.y,
		A.z*B.x - A.x*B.z,
		A.x*B.y - A.y*B.x
	);
	/*return Vector3
	(
		v1.y * v2.z - v2.y * v1.z,
		v1.z * v2.x - v2.z * v1.x,
		v1.x * v2.y - v2.x * v1.y
	);*/
}
Vector3 Vector3::Power(Vector3 v, float exp)
{
    return Vector3
    (
        abs(v.x) * v.x,
        abs(v.y) * v.y,
        abs(v.z) * v.z
    );
}
float Vector3::Dot(Vector3 v1, Vector3 v2)
{
	return	v1.x*v2.x + 
			v1.y*v2.y + 
			v1.z*v2.z;
}
